unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Buttons, Menus, Qt;

type
  TPointArray1 = array [1..7] of TPoint;
  TPointArray2 = array [1..15] of TPoint;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Label3: TLabel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    Button1: TButton;
    Button2: TButton;
    Label4: TLabel;
    Label5: TLabel;
    Button3: TButton;
    Button4: TButton;
    MainMenu1: TMainMenu;
    Hotkey1: TMenuItem;
    About1: TMenuItem;
    Label6: TLabel;
    Edit2: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Button5: TButton;
    Button6: TButton;
    Rightmove1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    function Ocircumgyrate(arr : TPointArray1; var Angle : real):TPointArray1;
    function Points(A, B : TPointArray1): TPointArray2;
    function UniteArray(A, B : TPointArray1; C : TPointArray2): TPointArray2;
    procedure Xsymmetry(Sender: TObject);
    procedure Ysymmetry(Sender: TObject);
    procedure XYsymmetry(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  x0, y0, R, r1 : integer;
  Alfa, Pi : real;
  A, B : TPointArray1;
  C : TPointArray2;
  cc : TPoint;

implementation

{$R *.dfm}

function TForm1.Ocircumgyrate(arr: TPointArray1; var Angle: real): TPointArray1;
var
  i, x, y : integer;
begin
  for i := 1 to Length(arr) do
  begin
    x := arr[i].X;
    y := arr[i].Y;
    arr[i].X := trunc( Cos(Angle)*x - Sin(Angle)*y );
    arr[i].Y := trunc( Sin(Angle)*x + Cos(Angle)*y );
  end;
  Result := arr;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Canvas.Pen.Width := 1;
  x0 := 425;
  y0 := 210;
  cc.X := 0;
  cc.Y := 0;
  R := 120;
  r1 := 50;
  Pi := 3.14159;
  Alfa := 2*Pi/7;
  C := Points(A, B);
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  D : TPointArray2;
  i : integer;
begin
  Canvas.Pen.color:=clwhite;
  Canvas.Brush.color := clwhite;
  Canvas.Rectangle(0,0,700,700);
  Canvas.Brush.Style := bsclear;

  Canvas.Pen.Color := clblue;
  Canvas.MoveTo(200,210);   Canvas.LineTo(650,210);
  Canvas.MoveTo(425,20);    Canvas.LineTo(425,420);
  Canvas.MoveTo(250,385);   Canvas.LineTo(600,35);

  for i := 1 to 15 do
  begin
    D[i].X := C[i].X + x0;
    D[i].Y := C[i].Y + y0;
  end;
  //D[15] := D[1];

  Canvas.Pen.Color := clblack;
  Canvas.Ellipse(x0-R,y0-R,x0+R,y0+R);
  Canvas.Polyline(D);
  Canvas.MoveTo(x0 + C[6].X, y0 + C[6].Y);
  Canvas.LineTo(x0 + C[14].X, y0 + C[14].Y);
  Canvas.MoveTo(x0 + C[2].X, y0 + C[2].Y);
  Canvas.LineTo(x0 + C[10].X, y0 + C[10].Y);
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  x0 := x0 - StrToInt(Edit1.Text);
  FormPaint(Sender);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  x0 := 425;
  y0 := 210;
  C := Points(A, B);
  FormPaint(Sender);
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin

  x0 := x0 + StrToInt(Edit1.Text);
  FormPaint(Sender);

end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
  y0 := y0 - StrToInt(Edit1.Text);
  FormPaint(Sender);
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
  y0 := y0 + StrToInt(Edit1.Text);
  FormPaint(Sender);
end;

procedure TForm1.Xsymmetry(Sender: TObject);
var
  i : integer;
begin
  y0 := 210 -y0 +210;
  for i := 1 to 15 do
  begin
    C[i].Y := -C[i].Y;
  end;
  FormPaint(Sender);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Xsymmetry(Sender);
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  Form1.Label4.Caption:='X='+IntToStr(X);
  Form1.Label5.Caption:='Y='+IntToStr(Y);
end;

procedure TForm1.Ysymmetry(Sender: TObject);
var
  i : integer;
begin
  x0 := 425 - x0 + 425;
  for i := 1 to 15 do
  begin
    C[i].X := -C[i].X;
  end;
  FormPaint(Sender);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Ysymmetry(Sender);
end;

procedure TForm1.XYsymmetry(Sender: TObject);
var
  i, temp, x, y : integer;
begin
  x := x0 - 425;
  y := y0 - 210;
  temp := x;
  x := -y;
  y := -temp;
  x0 := x + 425;
  y0 := y + 210;
  for i := 1 to 15 do
  begin
    temp := C[i].X;
    C[i].X := -C[i].Y;
    C[i].Y := -temp;
  end;
  FormPaint(Sender);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  XYsymmetry(Sender);
end;

function TForm1.Points(A, B : TPointArray1): TPointArray2;
var
  HalfAlfa : real;
begin
  A[1] := Point(0,-R);
  A[2] := Point( trunc( R * Sin(Alfa)   ), -trunc( R * Cos(Alfa)   ));
  A[3] := Point( trunc( R * Sin(2*Alfa) ), -trunc( R * Cos(2*Alfa) ));
  A[4] := Point( trunc( R * Sin(3*Alfa) ), -trunc( R * Cos(3*Alfa) ));
  A[5].X := -A[4].X; //Point(-trunc( R * Sin(3*Alfa) ), -trunc( R * Cos(3*Alfa) ));
  A[5].Y := A[4].Y;
  A[6].X := -A[3].X; //Point(-trunc( R * Sin(2*Alfa) ), -trunc( R * Cos(2*Alfa) ));
  A[6].Y := A[3].Y;
  A[7].X := -A[2].X; //Point(-trunc( R * Sin(Alfa)   ), -trunc( R * Cos(Alfa)   ));
  A[7].Y := A[2].Y;
  B[1] := Point(0,-r1);
  B[2] := Point( trunc( r1 * Sin(Alfa)   ),-trunc( r1 * Cos(Alfa) ));
  B[3] := Point( trunc( r1 * Sin(2*Alfa) ),-trunc( r1 * Cos(2*Alfa) ));
  B[4] := Point( trunc( r1 * Sin(3*Alfa) ),-trunc( r1 * Cos(3*Alfa) ));
  B[5].X := -B[4].X; //Point(-trunc( R * Sin(3*Alfa) ), -trunc( R * Cos(3*Alfa) ));
  B[5].Y := B[4].Y;
  B[6].X := -B[3].X; //Point(-trunc( R * Sin(2*Alfa) ), -trunc( R * Cos(2*Alfa) ));
  B[6].Y := B[3].Y;
  B[7].X := -B[2].X; //Point(-trunc( R * Sin(Alfa)   ), -trunc( R * Cos(Alfa)   ));
  B[7].Y := B[2].Y;
  HalfAlfa := Alfa/2;
  B := Ocircumgyrate(B,HalfAlfa);
  C := UniteArray(A, B, C);
  result := C;
end;

function TForm1.UniteArray(A, B: TPointArray1; C : TPointArray2): TPointArray2;
var
  i : integer;
begin
  for i := 1 to 7 do
  begin
    C[i*2-1] := A[i];
    C[i*2] := B[i];
  end;
  C[15] := A[1];
  result := C;
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  m : real;
begin
  m := StrToFloat(Edit2.Text);
  m := m/180;
  A := Ocircumgyrate(A,m);
  B := Ocircumgyrate(B,m);
  C := UniteArray(A,B,C);
  //FormPaint(Sender);
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = Key_Right then
  begin
  x0 := x0 + 10;
  FormPaint(Sender);
//  Repaint();
  end;

end;

end.

//    MessageDlg('shibai',mtInformation,[mbok],0);

